#!/usr/bin/env python
# coding=utf-8
'''
Author: ShenMeng
Date: 2021-08-30 13:21:56
FilePath: \kmoke\smart_theme\get_style.py
LastEditTime: 2021-09-16 14:53:12
'''
from .__style_template import TEMPLATE_STYLE

import os
import yaml
def __theme(name):
    _theme_file = os.path.join(os.path.dirname(__file__), 'theme', '{}.yml'.format(name)).replace('\\', '/')
    if os.path.isfile(_theme_file):
        return _theme_file

def from_config(in_path):
    _style = ''
    if os.path.isfile(in_path):
        _data = {}
        with open(in_path, 'rb') as f:
            _data = yaml.safe_load(f)
        if _data:
            _style = TEMPLATE_STYLE
            for _key in _data:
                new_value = _data[_key]
                if isinstance(new_value, int):
                    new_value = str(new_value)
                _style = _style.replace('@{}@'.format(_key), new_value)
    return _style

def get_preset(name='moon'):
    _theme_file = __theme(name)
    return from_config(_theme_file)
